package edu.neusoft.springhtmldemo.controller;

import edu.neusoft.springhtmldemo.domain.EarlyWarningLog;
import edu.neusoft.springhtmldemo.service.EarlyWarningLogService;
import edu.neusoft.springhtmldemo.util.StringToDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

@Controller
public class EarlyWarningLogController {
    @Autowired
    private EarlyWarningLogService service;

    /**
     * 展示所有
     * @return
     */
    @ResponseBody
    @RequestMapping("/showEarlyWarningLog")
    private List<EarlyWarningLog> showEarlyWarningLog(){
        List<EarlyWarningLog> lists=service.showEarlyWarningLog();
//        for (EarlyWarningLog list : lists) {
//            System.out.println(list);
//        }
        return lists;
    }

    /**
     * 根据各个条件进行查询
     * @param alarmNum
     * @param alarmBeginTime
     * @param alarmEndTime
     * @param robotNum
     * @param senserNum
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectEarlyWarningLog")
    private List<EarlyWarningLog> selectEarlyWarningLog(String alarmNum,String alarmBeginTime,String alarmEndTime,String alarmDetail,String robotNum,String senserNum){
        System.out.println(alarmBeginTime);
        if (alarmBeginTime.length()>0){
            alarmBeginTime=alarmBeginTime.substring(0,10);
        }
        if (alarmEndTime.length()>0){
            alarmEndTime=alarmEndTime.substring(0,10);
        }
        return service.selectEarlyWarningLog(alarmNum,alarmBeginTime,alarmEndTime,alarmDetail,robotNum,senserNum);
    }
}
